﻿using System;
using AiAsteriods.Game.State;

namespace AiAsteriods.Game.Entities.Agent {
  static class DecideRandom {
    public static ActionType Decide(int playerNum, GameStateAbstract gs) {
      //StateGrid.CalcGrid(playerNum, Global.GameStart.CurrentState);
      //StateGrid.DisplayGrid(playerNum);

      Random rand = new Random((int)DateTime.Now.Millisecond);
      ActionType result;

      double chanceLeft  = 0.2245f;
      double chanceRight = 0.2745f;
      double chanceAccel = 0.2745f;
      double chanceBrake = 0.2245f;
      double chanceSum = 0;
      double action = rand.NextDouble();

      if (action < chanceSum + chanceLeft || (chanceSum += chanceLeft) < 0)
        result = ActionType.LEFT;
      else if (action < chanceSum + chanceRight || (chanceSum += chanceRight) < 0)
        result = ActionType.RIGHT;
      else if (action < chanceSum + chanceAccel || (chanceSum += chanceAccel) < 0)
        result = ActionType.ACCEL;
      else if (action < chanceSum + chanceBrake)
        result = ActionType.BRAKE;
      else
        result = ActionType.SHOOT;

      return result;
    }
  }
}
